package com.xinggq.pay.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xinggq.pay.service.entity.AppCallbackConfigEntity;
import com.xinggq.pay.service.enums.CallbackTypeEnum;
import com.xinggq.pay.service.mapper.AppCallbackConfigMapper;
import com.xinggq.pay.service.service.AppCallbackConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 应用回调配置服务实现类
 * @author xinggq
 * @since 2025/9/16
 */
@Slf4j
@Service
public class AppCallbackConfigServiceImpl extends ServiceImpl<AppCallbackConfigMapper, AppCallbackConfigEntity> implements AppCallbackConfigService {

    /**
     * 根据支付渠道和回调类型查询启用的回调配置
     * @param payChannel 支付渠道
     * @param callbackType 回调类型
     * @return 回调配置
     */
    @Override
    public AppCallbackConfigEntity findEnabledByPayChannelAndType(String payChannel, CallbackTypeEnum callbackType) {
        LambdaQueryWrapper<AppCallbackConfigEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(AppCallbackConfigEntity::getPayChannel, payChannel)
                .eq(AppCallbackConfigEntity::getCallbackType, callbackType.getCode())
                .eq(AppCallbackConfigEntity::getStatus, 1);
        return this.getOne(wrapper);
    }
}